﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Gift.WebApp;
using Gift.Model;

namespace WebApp.admin.company
{
    public partial class companyLevel : BaseAdmin
    {
      
        tbCompanyLevel oCompanyLevel;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BuildForm();
            }
        }

        void BuildForm()
        {
            if (Request.QueryString["ot"] == "ed")
            {
                oCompanyLevel = BaseFactory.theCompanyLevel.GetModel(int.Parse(Request.QueryString["id"]));
                if (oCompanyLevel != null)
                {
                    this.txtCompanyLevel.Value = oCompanyLevel.LevelName;
                    this.txtOnSale.Value = oCompanyLevel.OnSale.ToString();
                    this.txtSortOrder.Value = oCompanyLevel.sortOrder.ToString();
                }
               
            }
        }


        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["ot"] == "ed")
            {
                oCompanyLevel = BaseFactory.theCompanyLevel.GetModel(int.Parse(Request.QueryString["id"]));
                if (oCompanyLevel != null)
                {
                    oCompanyLevel.LevelName = this.txtCompanyLevel.Value.Trim();
                    oCompanyLevel.OnSale = decimal.Parse(this.txtOnSale.Value);
                    oCompanyLevel.sortOrder = int.Parse(this.txtSortOrder.Value);
                }

                if (BaseFactory.theCompanyLevel.Update(oCompanyLevel))
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");window.location.href='companyLevelList.aspx';</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
                }

            }
            else
            {
                oCompanyLevel = new tbCompanyLevel();
                oCompanyLevel.LevelName = this.txtCompanyLevel.Value.Trim();
                oCompanyLevel.OnSale = decimal.Parse(this.txtOnSale.Value);
                oCompanyLevel.sortOrder = int.Parse(this.txtSortOrder.Value);
                oCompanyLevel.creater = int.Parse(base.Administrator.AdminUserId);
                oCompanyLevel.companyId = int.Parse(base.Administrator.CompanyId);
                oCompanyLevel.createTime = DateTime.Now;
                if (BaseFactory.theCompanyLevel.Add(oCompanyLevel) > 0)
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加成功！\");window.location.href='companyLevelList.aspx';</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加失败！\");</script>");
                }
            }

        }
    }
}